#!/bin/bash
###SHELLPACK preamble mpas v6.2
GIT_LOCATION=https://github.com/MPAS-Dev/MPAS-Model
MIRROR_LOCATION="$WEBROOT/mpas/"

if [ "$MPAS_OPENMPI_VERSION" != "" ]; then
	###SHELLPACK mpi_setup_deps MPAS_OPENMPI_VERSION
	###SHELLPACK mpi_setup_env MPAS_OPENMPI_VERSION MPAS_MPI_PATH MPAS_MPI_LIBPATH
fi

###SHELLPACK parseargBegin
###SHELLPACK parseargEnd

###SHELLPACK git_fetch mpas-${VERSION}.tar.gz mpas-${VERSION}-installed
###SHELLPACK build_start mpas-${VERSION}-installed

# Additional configuration to build MPAS in both x86_64 and aaarch64:
#- removes -m64
#- use $(MMTESTS_LIBDIR) instead of "lib"
sed -i -e "s/\-m64//" Makefile
sed -i -e "s/-L\$(PNETCDF)\/lib/-L\$(PNETCDF)\/$MMTESTS_LIBDIR/" Makefile

# gcc-10 requirements
# - adds -fallow-invalid-boz
if [ "$MMTESTS_TOOLCHAIN" = "gcc-10" -o "$MMTESTS_TOOLCHAIN" = "hpc-gcc-10" ]; then
	sed -i -e 's/FFLAGS_PROMOTION = /& -fallow-invalid-boz /' Makefile
fi

export PIO="$SHELLPACK_SOURCES/mpasdeps-installed"
export PNETCDF="$SHELLPACK_SOURCES/mpasdeps-installed"

###SHELLPACK make gfortran CORE=init_atmosphere USE_PIO2=true OPENMP=true
###SHELLPACK make gfortran CORE=atmosphere USE_PIO2=true AUTOCLEAN=true OPENMP=true

echo mpas installed successfully
exit $SHELLPACK_SUCCESS
